// 定义基础域名
import config from './cdnurl.js';

const request = (type, url, data) => {
	uni.onNetworkStatusChange((res) => {
		if (!res.isConnected) {
			uni.showToast({
				title: '网络连接不可用！',
				icon: 'none',
			});
		}
		return false;
	});

	return new Promise((resolve, reject) => {
		uni.request({
			method: type,
			url: config.cdnurl + url,
			data,
			header: {
				Authorization: 'Bearer' + ' ' + uni.getStorageSync('token'),
			},
		}).then((response) => {
			resolve(response.data);
		}).catch((error) => {
			reject(error);
		});
	});
};
export default request;